import Request from '@/utils/requset.js'
let request = new Request().http

function removeStr(obj) {
  if(obj) {
    let removePropertyOfNull=function(obj){
      Object.keys(obj).forEach(item=>{
        if(!obj[item])  delete obj[item]
      })
      return obj;
    }
    removePropertyOfNull(obj)
  }
  return obj?obj:''
}


// 商品列表
const getGoodsList = (params) => {
	return request({
	    url: "/nailGoodsInfo/queryList",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 通过id查询某件商品
const getGoodsInfo= (params) => {
	return request({
	    url: "/nailGoodsInfo/queryById",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 购物车减掉商品
const getAddCart= (params) => {
	return request({
	    url: "/nailGoodsInfo/addCart",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 购物车减掉商品
const getReduceCart= (params) => {
	return request({
	    url: "/nailGoodsInfo/subCart",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 创建商品订单
const createGoodsOrder= (params) => {
	return request({
	    url: "/nailGoodsOrder/createGoodsOrder",
	    method: "POST",
	    data: removeStr(params),
	})
}


// 订单支付(获取key)
const nailPayOrder= (params) => {
	return request({
	    url: "/nailPayOrder/pay",
	    method: "POST",
	    data: removeStr(params),
	})
}

// 创建打印订单
const printCreateOrder= (params) => {
	return request({
	    url: "/nailPrintOrder/createOrder",
	    method: "POST",
	    data: removeStr(params),
	})
}

// 取消订单退款
const refundApply= (params) => {
	return request({
	    url: "/nailPayOrder/refundApply",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 购物车订单结算
const settlementCartGoodsOrder= (params) => {
	return request({
	    url: "/nailGoodsOrder/settlementCartGoodsOrder",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 购物车列表
const getCartList = (params) => {
	return request({
	    url: "/nailGoodsInfo/cartList",
	    method: "GET",
	    params: removeStr(params),
	})
}

// 购物车减掉商品
const getSubCart = (params) => {
	return request({
	    url: "/nailGoodsInfo/subCart",
	    method: "GET",
	    params: removeStr(params),
	})
}


export {
	getGoodsList,
	getGoodsInfo,
	getAddCart,
	getReduceCart,
	nailPayOrder,
	createGoodsOrder,
	printCreateOrder,
	refundApply,
	settlementCartGoodsOrder,
	getCartList,
	getSubCart
}